// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Sega Object
// Script Author: Christan Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 1 : TYPE_SEGA
public alias 256 : GROUP_PLAYERS
public alias 65536 : HITBOX_AUTO
public alias arrayPos6 : currentPlayer
public alias arrayPos7 : playerCount

// Function declarations
reserve function Sega_Function0

function Sega_Function0
	CheckTouchRect(0, 0, screen.xsize, screen.ysize)
	if checkResult == -1
		object.value4 = 0
	end if
	if object.value4 == 0
		temp0 = screen.xcenter
		switch object.value3
		case 0
			temp0 -= 93
			temp1 = temp0
			temp1 += 39
			break
		case 1
			temp0 -= 50
			temp1 = temp0
			temp1 += 42
			break
		case 2
			temp0 -= 6
			temp1 = temp0
			temp1 += 42
			break
		case 3
			temp0 += 36
			temp1 = temp0
			temp1 += 58
			break
		end switch
		CheckTouchRect(temp0, 90, temp1, 150)
		if checkResult > -1
			object.value4 = 1
			object.value3++
			if object.value3 == 4
				PlaySfx(SfxName[Ring L], 0)
				options.stageSelectFlag = 1
			end if
		end if
		temp0 = screen.xcenter
		switch object.value5
		case 0
			temp0 += 36
			temp1 = temp0
			temp1 += 58
			break
		case 1
			temp0 -= 6
			temp1 = temp0
			temp1 += 42
			break
		case 2
			temp0 -= 50
			temp1 = temp0
			temp1 += 42
			break
		case 3
			temp0 -= 93
			temp1 = temp0
			temp1 += 39
			break
		end switch
		CheckTouchRect(temp0, 90, temp1, 150)
		if checkResult > -1
			object.value4 = 1
			object.value5++
			if object.value5 == 4
				PlaySfx(SfxName[Ring L], 0)
				options.region ^= 1
			end if
		end if
	end if
end function


event ObjectMain
	switch object.state
	case 0
		object.alpha = 0
		object.inkEffect = INK_ALPHA
		object.value0 = 320
		SetScreenFade(0, 0, 0, object.value0)
		object.state++
		break
	case 1
		if object.value0 > 0
			object.value0 -= 8
		else
			object.value2 = screen.xcenter
			object.value2 -= 104
			object.alpha = 128
			object.state++
		end if
		SetScreenFade(0, 0, 0, object.value0)
		break
	case 2
		temp0 = screen.xcenter
		temp0 += 112
		if object.value2 < temp0
			object.value2 += 4
		else
			object.alpha = 0
			object.state++
		end if
		break
	case 3
		if object.alpha < 208
			object.alpha += 8
		else
			object.alpha = 255
			object.state++
		end if
		CallFunction(Sega_Function0)
		break
	case 4
		object.value0++
		if object.value0 == 160
			object.value0 = 0
			object.state = 5
		end if
		if object.value0 == 2
			PlaySfx(SfxName[Sega Chant], 0)
		end if
		if options.gameMode == 0
			CallFunction(Sega_Function0)
		end if
		break
	case 5
		if object.value0 < 256
			object.value0 += 8
			SetScreenFade(0, 0, 0, object.value0)
		else
			ResetObjectEntity(object.entityPos, TypeName[SHC Splash], 0, object.xpos, object.ypos)
			SetScreenFade(0, 0, 0, 255)
		end if
		break
	end switch
end event


event ObjectDraw
	DrawRect(0, 0, screen.xsize, screen.ysize, 224, 224, 224, 255)
	if object.alpha > 8
		DrawSpriteScreenFX(0, FX_INK, screen.xcenter, screen.ycenter)
	end if
	if object.state == 2
		temp0 = object.value2
		temp0 -= 10
		temp0 -= screen.xsize
		DrawRect(temp0, 91, screen.xsize, 58, 224, 224, 224, 255)
		temp0 = object.value2
		temp0 -= 10
		DrawRect(temp0, 91, 4, 58, 224, 224, 224, 192)
		temp0 += 4
		DrawRect(temp0, 91, 4, 58, 224, 224, 224, 160)
		temp0 += 8
		DrawRect(temp0, 91, 4, 58, 224, 224, 224, 160)
		temp0 += 4
		DrawRect(temp0, 91, 4, 58, 224, 224, 224, 192)
		temp0 += 4
		DrawRect(temp0, 91, screen.xsize, 58, 224, 224, 224, 255)
		DrawSpriteScreenXY(1, screen.xcenter, screen.ycenter)
	end if
end event


event ObjectStartup
	LoadSpriteSheet("Title/Title.gif")
	SpriteFrame(-93, -29, 188, 58, 323, 242)
	SpriteFrame(-125, -29, 252, 58, 259, 301)
	options.touchControls = 0
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
